#include "GameServer.h"

#include "_Global/GameCommon.h"
#include "_Global/Platform/Platform.h"

#include <QApplication>
#include <QDir>



int main(int argc, char *argv[])
{
    //QCoreApplication::applicationDirPath()
    QApplication app(argc, argv);


    QDir dirLogPath("Logs");
    if(!dirLogPath.exists())    /**< 如果目标目录不存在，则进行创建 */
        if(!dirLogPath.mkpath(dirLogPath.absolutePath()))
            return -1;

    MessageHandlerInfo* pMessageHandlerInfo = MessageHandlerInfo::create();
    pMessageHandlerInfo->m_strDatetimeFormat = QString("yyyy-MM-dd");
    pMessageHandlerInfo->m_strInfoFile = QString("Logs/Info_%1.txt");
    pMessageHandlerInfo->m_strDebugFile = QString("Logs/Debug_%1.txt");
    pMessageHandlerInfo->m_strWarningFile = QString("Logs/Warning_%1.txt");
    pMessageHandlerInfo->m_strCriticalFile = QString("Logs/Critical_%1.txt");
    pMessageHandlerInfo->m_strFatalFile = QString("Logs/Fatal_%1.txt");
    pMessageHandlerInfo->m_strOthersFile = QString("Logs/Others_%1.txt");



#ifdef QT_NO_DEBUG
    qInstallMessageHandler(MessageHandlerInfo::MessageHandler);

    //注冊异常捕获函数
    SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)ApplicationCrashHandler);
#else
    //qInstallMessageHandler(MessageHandlerInfo::MessageHandler);
#endif



    qDebug()<<"Main ThreadId:"<<QThread::currentThreadId();

    GameServer w;
    _ClientsGroupInfo::SetGroupExtraDataCallback = GameServer::Fn_SetGroupExtraData_Callback;
    _ClientsGroupInfo::UnsetGroupExtraDataCallback = GameServer::Fn_UnsetGroupExtraData_Callback;
    w.initOnce();

    QObject::connect(&app, &QApplication::aboutToQuit, [=]()
    {
        //if(pMessageHandlerInfo != nullptr)
        //    delete pMessageHandlerInfo;
    });
    return app.exec();
}
